<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<link rel="stylesheet" href="../css/student.css">

<body style="background: url('../img/bg-min.jpg');background-size: cover;">
    <div id="app5">
        <div class="login-state">
            <el-card class="box-card">
                <div slot="header" class="clearfix">
                    <h4>系统登录</h4>
                </div>
                <el-form :model="ruleForm" ref="ruleForm" label-width="80px" class="studentForm">
                    <el-form-item label="账号" prop="account">
                        <el-input v-model="ruleForm.account" style="width: 86%;" placeholder="账号"></el-input>
                    </el-form-item>

                    <el-form-item label="密码" prop="password">
                        <el-input v-model="ruleForm.password" style="width: 86%;" placeholder="密码" show-password>
                        </el-input>
                    </el-form-item>
                    <div class="login-btn">
                        <el-button type="primary" class="login-btn-state" @click="login">登录</el-button>
                    </div>
                </el-form>
            </el-card>
        </div>
    </div>

</body>
<script>
    var app5 = new Vue({
        el: '#app5',
        url: '127.0.0.1:8080',
        data: {
            url: 'http://127.0.0.1:8080',
            ruleForm: {
                account: "",
                password: "",
            },
        },
        methods: {
            login: function () {
                if (!this.ruleForm.account) return this.$message({
                    message: '请输入账号',
                    type: 'warning'
                })
                if (!this.ruleForm.password) return this.$message({
                    message: '请输入密码',
                    type: 'warning'
                })

                axios.get(this.url + '/user/get', {
                    params: {
                        account: this.ruleForm.account,
                        password: this.ruleForm.password
                    }
                }).then(function (res) {
                    if (res.data.msg == 'success') {
                        res = res.data.obj;
                        window.localStorage.setItem("type", res.type) //本地保存用户角色
                        window.localStorage.setItem("userName", res.account) //本地保存用户角色
                        window.localStorage.setItem("creator", res.id) //本地保存用户id
                        if (res.teacher != null) {
                            if (res.teacher.name != null) window.localStorage.setItem("name", res.teacher.name)//保存基本信息
                            if (res.teacher.sex != null) window.localStorage.setItem("sex", res.teacher.sex)//保存基本信息
                            if (res.teacher.mobile != null) window.localStorage.setItem("mobile", res.teacher.mobile)//保存基本信息
                        }
                        if (res.student != null) {
                            if (res.student.name != null) window.localStorage.setItem("name", res.student.name)//保存基本信息
                            if (res.student.sex != null) window.localStorage.setItem("sex", res.student.sex)//保存基本信息
                            if (res.student.mobile != null) window.localStorage.setItem("mobile", res.student.mobile)//保存基本信息
                        }
                        if (res.student != null) {
                            if (res.student.name != null) window.localStorage.setItem("name", res.student.name)//保存基本信息
                            if (res.student.sex != null) window.localStorage.setItem("sex", res.student.sex)//保存基本信息
                            if (res.student.mobile != null) window.localStorage.setItem("mobile", res.student.mobile)//保存基本信息
                        }
                        if (res.type == 0) {
                            //admin || 老师
                            window.location.href = "teacherInfo.html"
                        } else if (res.type == 1) {
                            //学生
                            window.location.href = "studentInfo.html"
                        }

                    }

                })
                // window.location.href = "member.html"
            }
        }
    });
</script>

</html>
